<template>
  <div class="pageWrapper">
    <common-header />
    <div class="card">
      <div class="title">反馈内容</div>
      <textarea id="content" @click="onTextArea" v-model="submitForm.resultContent" placeholder="请输入异议反馈内容"></textarea>
    </div>
    <div class="submit-btn btn-active" @click="onSubmit">提交</div>
  </div>
</template>

<script>
import { saveResultAssess, creatResultAssess } from "@/api/appraisalResults";
import { Toast } from "vant";
export default {
  data() {
    return {
      submitForm: {
        appraisalId: 21,
        resultContent: "",
        dissentType: 1
      }
    };
  },
  created() {
    this.submitForm.appraisalId = this.$route.query.id;
    this.submitForm.dissentType = this.$route.query.is_year == "1" ? "2" : "1";
  },
  methods: {
    onTextArea() {
      this.$nextTick(() => {
        document.querySelector('#content').focus();
      })
    },
    onSubmit() {
      if (!this.submitForm.resultContent) {
        Toast("请输入反馈内容");
        return;
      }
      if (this.$route.query.from == "list") {
        let form = {
          id: this.$route.query.oid,
          resultContent: this.submitForm.resultContent
        };
        saveResultAssess(form).then(res => {
          if (res.code == 200) {
            this.linkList();
          } else {
            Toast(res.msg);
          }
        });
      } else {
        creatResultAssess(this.submitForm).then(res => {
          if (res.code == 200) {
            this.linkList();
          } else {
            Toast(res.msg);
          }
        });
      }
    },
    linkList() {
      if (this.$route.query.from == "list") {
        this.$router.back();
      } else {
        this.$router.replace({
          path: "/appraisalResults/feedback",
          query: {
            id: this.submitForm.appraisalId,
            is_year: this.$route.query.is_year || "0"
          }
        });
      }
    }
  }
};
</script>

<style scoped lang="scss">
.card {
  background: #fff;
  border-radius: 8px;
  margin: 20px 16px;
  padding: 16px;

  .title {
    line-height: 22px;
    color: #000;
    font-size: 16px;
    margin-bottom: 12px;
  }

  textarea {
    color: #333;
    font-size: 14px;
    line-height: 20px;
    padding: 0;
    border: none;
    width: 100%;
    resize: unset;
    height: 128px;

    &::placeholder {
      color: #b2b2b2;
    }
  }
}

.submit-btn {
  position: fixed;
  left: 16px;
  bottom: 64px;
  width: 343px;
  text-align: center;
  line-height: 52px;
  border-radius: 12px;
  color: #fff;
  background: #2492ff;
  font-size: 14px;
}
</style>
